<?php

namespace App\Console\Commands;

use App\Console\Base;
use App\Models\Message;
use App\Models\DemoUser;

class DeleteDemoUser extends Base
{
    //试玩账号有效时长(单位：天)
    const VALID_TIME =  3;
    /**
     * 控制台命令 signature 的名称。
     *
     * @var string
     */
    protected $signature = self::PREFIX . 'deleteDemoUser';

    /**
     * 控制台命令说明。
     *
     * @var string
     */
    protected $description = 'deleteDemoUser';

    /**
     * 是否厅命令
     *
     * @var bool
     */
    protected $isHallCmd = true;

    /**
     * 执行控制台命令。
     *
     * @return mixed
     */
    public function handle()
    {
        $deleteIds = [];
        $demoUsers = DemoUser::get();
        foreach ($demoUsers as $user){
            $expiredTime = strtotime($user['created_at']."+".self::VALID_TIME." day");
            if(time() >= $expiredTime){
                $deleteIds[] = $user['id'];
            }
        }
        if($deleteIds){
            DemoUser::whereIn("id", $deleteIds)->delete();
        }
    }
}
